<script setup lang="ts">
import { onMounted, ref } from 'vue'

const inpRef = ref<HTMLInputElement | null>(null)
onMounted(() => {
  // 1. 非空断言
  // inpRef.value!.focus()

  // 2. 判断
  if (inpRef.value) {
    inpRef.value.focus()
  }
})

const aRef = ref<HTMLAnchorElement | null>(null)
onMounted(() => {
  aRef.value!.href = '212121'
})
</script>

<template>
  <div>
    <input type="text" ref="inpRef">
    <a href="#">点我呀</a>
  </div>
</template>

<style scoped></style>
